package x.y.z;

public class LeetCode_1109 {
    private int[] diff;

    public int[] corpFlightBookings(int[][] bookings, int n) {
        diff = new int[n];
        for (int[] book : bookings) {
            increment(book[0] - 1, book[1] - 1, book[2]);
        }
        int[] result = new int[n];
        result[0] = diff[0];
        for (int i = 1; i < n; i++) {
            result[i] = result[i - 1] + diff[i];
        }
        return result;
    }

    public void increment(int i, int j, int val) {
        diff[i] += val;
        if (j + 1 < diff.length) {
            diff[j + 1] -= val;
        }
    }
}
